//**************************************************************************/
// Copyright (c) 1998-2007 Autodesk, Inc.
// All rights reserved.
// 
// These coded instructions, statements, and computer programs contain
// unpublished proprietary information written by Autodesk, Inc., and are
// protected by Federal copyright law. They may not be disclosed to third
// parties or copied or duplicated in any form, in whole or in part, without
// the prior written consent of Autodesk, Inc.
//**************************************************************************/
// DESCRIPTION: Appwizard generated plugin
// AUTHOR: 
//***************************************************************************/

#include "maxexporter.h"

#define maxexporter_CLASS_ID	Class_ID(0x9ffdf2cb, 0x57a38a45)

class maxexporter : public SceneExport {
	public:
		
		static HWND hParams;
		
		int				ExtCount();					// Number of extensions supported
		const TCHAR *	Ext(int n);					// Extension #n (i.e. "3DS")
		const TCHAR *	LongDesc();					// Long ASCII description (i.e. "Autodesk 3D Studio File")
		const TCHAR *	ShortDesc();				// Short ASCII description (i.e. "3D Studio")
		const TCHAR *	AuthorName();				// ASCII Author name
		const TCHAR *	CopyrightMessage();			// ASCII Copyright message
		const TCHAR *	OtherMessage1();			// Other message #1
		const TCHAR *	OtherMessage2();			// Other message #2
		unsigned int	Version();					// Version number * 100 (i.e. v3.01 = 301)
		void			ShowAbout(HWND hWnd);		// Show DLL's "About..." box

		BOOL SupportsOptions(int ext, DWORD options);
		int				DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts=FALSE, DWORD options=0);

		//Constructor/Destructor
		maxexporter();
		~maxexporter();
};



class maxexporterClassDesc : public ClassDesc2 
{
public:
	virtual int IsPublic() 							{ return TRUE; }
	virtual void* Create(BOOL /*loading = FALSE*/) 		{ return new maxexporter(); }
	virtual const TCHAR *	ClassName() 			{ return GetString(IDS_CLASS_NAME); }
	virtual SClass_ID SuperClassID() 				{ return SCENE_EXPORT_CLASS_ID; }
	virtual Class_ID ClassID() 						{ return maxexporter_CLASS_ID; }
	virtual const TCHAR* Category() 				{ return GetString(IDS_CATEGORY); }

	virtual const TCHAR* InternalName() 			{ return _T("maxexporter"); }	// returns fixed parsable name (scripter-visible name)
	virtual HINSTANCE HInstance() 					{ return hInstance; }					// returns owning module handle
	

};


ClassDesc2* GetmaxexporterDesc() { 
	static maxexporterClassDesc maxexporterDesc;
	return &maxexporterDesc; 
}





INT_PTR CALLBACK maxexporterOptionsDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	static maxexporter *imp = NULL;

	switch(message) {
		case WM_INITDIALOG:
			imp = (maxexporter *)lParam;
			CenterWindow(hWnd,GetParent(hWnd));
			return TRUE;

		case WM_CLOSE:
			EndDialog(hWnd, 0);
			return 1;
	}
	return 0;
}


//--- maxexporter -------------------------------------------------------
maxexporter::maxexporter()
{

}

maxexporter::~maxexporter() 
{

}

int maxexporter::ExtCount()
{
	return 1;
}

const TCHAR *maxexporter::Ext(int n)
{		
	return _T("SDF");
}

const TCHAR *maxexporter::LongDesc()
{
	return _T("Binary data exporter");
}
	
const TCHAR *maxexporter::ShortDesc() 
{			
	return _T("Simple Data Format");
}

const TCHAR *maxexporter::AuthorName()
{			
	return _T("Marcelo R. Villarreal Fasanelli");
}

const TCHAR *maxexporter::CopyrightMessage() 
{	
	return _T("No Copyright");
}

const TCHAR *maxexporter::OtherMessage1() 
{		
	//TODO: Return Other message #1 if any
	return _T("");
}

const TCHAR *maxexporter::OtherMessage2() 
{		
	//TODO: Return other message #2 in any
	return _T("");
}

unsigned int maxexporter::Version()
{				
	return 100;
}

void maxexporter::ShowAbout(HWND hWnd)
{			
	// Optional
}

BOOL maxexporter::SupportsOptions(int ext, DWORD options)
{
	return TRUE;
}


int	maxexporter::DoExport(const TCHAR *name, ExpInterface *ei, Interface *i, BOOL suppressPrompts, DWORD options)
{
	/*
	if(!suppressPrompts)
		DialogBoxParam(hInstance, 
				MAKEINTRESOURCE(IDD_PANEL), 
				GetActiveWindow(), 
				maxexporterOptionsDlgProc, (LPARAM)this);
	*/

	try {
		Modeling::AppStream* stream;
		Modeling::Scene* scene = new Modeling::Scene();
		
		stream = new MaxExporter::MaxStream(i->GetRootNode()); 
		stream->read(scene);
		delete stream;

		stream = new Modeling::TextStream(name, "w");
		stream->write(scene);
		delete stream;

		delete scene;
	} catch(Exceptions::Exception& e) {
		return FALSE;
	}

	return TRUE;
}
